# creational pattern（创建型）
# -> simple factory pattern（简单工厂模式）
from abc import ABC, abstractmethod
########################################
# 产品
class Button(ABC):
    @abstractmethod
    def on_click(self):
        pass

class WindowsButton(Button):
    def on_click(self):
        print('I\'m a WindowsButton')

class MacButton(Button):
    def on_click(self):
        print('I\'m a MacButton')

class LinuxButton(Button):
    def on_click(self):
        print('I\'m a LinuxButton')

#######################################
# 工厂
class Creator(object):
    def createButton(self, platform):
        if platform == 'windows':
            return WindowsButton()
        elif platform == 'mac':
            return MacButton()
        elif platform == 'linux':
            return LinuxButton()
        else:
            raise AttributeError('invalid platform!')

#######################################
def main():
    creator = Creator()
    button = creator.createButton('windows')
    button.on_click()

if __name__ == '__main__':
    main()
